<!DOCTYPE html>
<html class="x-admin-sm">
  <head>
    <meta charset="UTF-8">
    <title>客户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__ADMIN__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
    <script type="text/javascript" src="__ADMIN__/js/cookie.js"></script>
    <style>
        .layui-btn+.layui-btn{
            margin-left: 0;
        }
        .layui-font-blue{color:#01AAED!important}
        tr, td{font-size: 14px !important;}
    </style>
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite>{$nav}</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3" style="line-height:30px"></i></a>
    </div>
    <div class="x-body x-admin">
      <xblock>
          
        <!--<button class="layui-btn" onclick="x_admin_show('录入客户','add')"><i class="layui-icon"></i>录入客户</button>-->
        <div class="layui-card-body" style="padding-left: 0;float:left;padding-top:0;">
          <form class="layui-form layui-col-space5" action="" method="get">
              <div class="layui-inline layui-show-xs-block">
                  <input style="width:260px;" type="text" name="keywords" id="search" value="{:input()['keywords']}" placeholder="请输入客户姓名、赛事名称、联系方式" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-inline layui-show-xs-block">
                  <button class="layui-btn" id="search-btn"><i class="layui-icon"></i></button>
              </div>
              <div class="layui-inline layui-show-xs-block">
                  <a class="layui-btn" href="/admin.php/client/{$lst}">全部</a>
              </div>
              <div class="layui-inline layui-show-xs-block">
                  <a class="layui-btn" href="/admin.php/client/{$lst}/only_my/1">我录入的</a>
              </div>
              <div class="layui-inline layui-show-xs-block">
                  <a class="layui-btn" href="/admin.php/client/{$lst}/is_group/1">小组</a>
              </div>
          </form>
        </div>
        <span class="x-right" style="line-height:40px">共有数据：{$count}条</span>
      </xblock>
      <div class="layui-table-body layui-table-main" style="width: 100%;">
      <table class="layui-table layui-form">
        <thead>
          <tr>
            <th width="50">编号</th>
            <th>赛事名称</th>
            <th width="100">地区(市、县)</th>
            <th width="80">比赛时间</th>
            <th width="60">客户姓名</th>
            <th width="150">联系方式</th>
            <th width="60">营销</th>
            <th width="80">录入时间</th>
            <th  width="120" style="text-align: center;">操作</th>
        </thead>
        <tbody>
          {volist name="clientRes" id="client"}
          {php}
          $client['scount'] = getCountByClientId($client['union_id'],'all','array');
          $client['phone'] = json_decode($client['phone'],true);
          {/php}
          <tr>
            <td>{$client.id}</td>
            <td>{$client['scount'][4]['text']}{$client['scount'][3]['text']}{$client['scount'][1]['text']}{$client.activity}</td>
            <td>{$client.address}</td>
            <td>{$client.activity_time}</td>
            <td>{$client.name}</td>
            <td>
              <div>电话:{volist name="$client.phone" id="phone"}{:hideContactNum($phone)}<br>{/volist}微信:{:hideContactNum($client.wx)} <a href="javascript:;" class="show-true-num layui-font-blue">显示</a></div>
              <div style="display:none" class="true-num">电话:{volist name="$client.phone" id="phone"}{$phone}<br>{/volist}微信:{$client.wx}{if condition="$client.wx_code"}<br><span class="wx-code-btn layui-font-blue" wx-code="{$client.wx_code}">微信二维码</span>{/if}</div>
            </td>
            <td>{$client.aname}</td>
            <td>{$client.add_time|date="Y-m-d",###}</td>
            <td class="td-manage" style="text-align: center;">
                {if condition="$client.status eq 0 && $client['scount'][1]['count']+$client['scount'][3]['count'] < 5"}
                    <a title="关联" class="layui-btn layui-btn-normal layui-btn-xs" lay-filter="guanlian" lay-submit="" lay-id="{$client.id}" href="javascript:;">
                        <i class="layui-icon">&#xe669;关联</i>
                    </a>
                {/if}
                <a title="投诉" class="layui-btn layui-btn-normal layui-btn-xs" onclick="x_admin_show('投诉操作','{:url('Client/complaintClient')}/id/{$client.id}')" href="javascript:;">
                    投诉
                </a>
            </td>
          </tr>
          {/volist}
        </tbody>
      </table>
    </div>
      <div class="page">
        <div>
          {$clientRes->render()}
        </div>
      </div>
    </div>

    <script>

      $('.show-true-num').click(function(){
          $('.true-num').hide();
          $('.show-true-num').parent().show();
          $(this).parent().hide();
          $(this).parent().next('.true-num').show();
      });

      layui.use(['form','layer','jquery'], function(){
        var form = layui.form,
        layer = layui.layer;



        /*管理员开关*/
        form.on('switch(status)', function(data){
          var obj=data.elem;
          var id = data.elem.id;
          var status = data.value;
          $.ajax({
              type:'POST',
              dataType:'json',
              data:{status:status,id:id},
              url:"{:url('Admin/changeStatus')}",
              success:function(o){
                if(o.icon == 1){
                  $(obj).attr('value',1);
                }else{
                  $(obj).attr('value',0);
                }
                layer.msg(o.msg,{icon: o.icon,time:1000});
              }
            });
        });

        $('.wx-code-btn').click(function(){
          layer.open({
            type: 1,
            title: '扫一扫',
            area: ['310px', '360px'],
            content: '<img src="'+$(this).attr('wx-code')+'" style="width:305px;height:305px;" > '
          });
        })
        
        //监听提交
        form.on('submit(guanlian)', function(data){
                var client_id = $(this).attr('lay-id');
                layer.confirm('确定将该客户提取成自有客户吗？', {icon: 3, title:'关联操作'}, function(index){
                    //do something
                    $.ajax({
                        type:'POST',
                        dataType:'json',
                        data:{client_id:client_id},
                        url:"{:url('Client/guanlian')}",
                        success:function(obj){
                          if(obj.status == -2)
                          {
                            layer.open({
                              type: 2,
                              title: '申请继续关联客户',
                              shadeClose: false,
                              shade: false,
                              area: ['800px', '600px'],
                              content: '{:url('apply/guanlian')}/client_id/' + client_id
                            });
                            return;
                          }
                          layer.msg(obj.msg, {icon: obj.icon,time: 2000},function(){
                            // 获得frame索引
                            // var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            // parent.layer.close(index);
                            // 可以对父窗口进行刷新 
                            //x_admin_father_reload();
                            location.reload();
                          });
                        }
                    });
                  layer.close(index);
                });
            return false;
        });
        
      });

    </script>
  </body>

</html>